using SqlSugar;
using IM.Easy.Core.Services;
using IM.Easy.Core.Utils;
using IM.Easy.Infrastructure.Query;
using IM.Easy.Core.Extensions;
using IM.Easy.Entity.Scheduled;
using IM.Easy.ScheduledServices.Dtos;
using IM.Easy.ScheduledServices.IServices;

namespace IM.Easy.ScheduledServices.Services
{
    public class JobExecutionHistoryService : AppServices<JobExecutionHistory>, IJobExecutionHistoryService
    {

        public JobExecutionHistoryService(ISqlSugarClient db) : base(db)
        {

        }

        public JobExecutionHistory Create(JobExecutionHistory entity)
        {
            // TODO: 添加创建逻辑
            return Context.Insertable(entity).ExecuteReturnEntity();
        }

        public JobExecutionHistory GetById(string id)
        {
            // TODO: 添加获取逻辑
            return Context.Queryable<JobExecutionHistory>().InSingle(id);
        }
        
        public PageResponse<JobExecutionHistory> GetPageList(JobExecutionHistoryQueryDto query)
        {
            var queryable = Context.Queryable<JobExecutionHistory>();
            var exp = Expressionable.Create<JobExecutionHistory>();
            exp = exp
;
            var page = queryable
                 .Where(exp.ToExpression())
                 .ToPageList<JobExecutionHistory,JobExecutionHistory>(query);
             return page;
        }

        public bool Update(JobExecutionHistory entity)
        {
            // TODO: 添加更新逻辑
            return Context.Updateable(entity).ExecuteCommandHasChange();
        }

        public bool Delete(params string[] HistoryId)
        {
            // TODO: 添加删除逻辑
            return Context.Deleteable<JobExecutionHistory>(HistoryId).ExecuteCommandHasChange();
        }
    }
}
